home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 July / macformat-026.iso / mac / Shareware City / Developers / WASTE Object Handlers v1.0 ƒ / Other Source / SendFinderOpen.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-11  |  3.1 KB  |  137 lines  |  [TEXT/MPCC]

  1. #include "SendFinderOpen.h"
  2.  
  3. #define kFinderSig            'FNDR'
  4. #define kAEFinderEvents        'FNDR'
  5. #define kSystemType            'MACS'
  6.  
  7. #define    kAEOpenSelection    'sope'
  8. #define keySelection        'fsel'
  9.  
  10. OSErr SendFinderOpenAE(FSSpec *theDoc)
  11. {
  12. AppleEvent            aeEvent;
  13. AEDesc                myAddressDesc;
  14. AEDesc                aeDirDesc;
  15. AEDesc                listElem;
  16. AEDescList            fileList;
  17. FSSpec                dirSpec;
  18. AliasHandle            dirAlias;
  19. AliasHandle            fileAlias;
  20. ProcessSerialNumber    process;
  21. OSErr                myErr;
  22. OSType            FndrType = 'MACS';
  23.     
  24.     /*
  25.      * Get the psn of the Finder and create the target address for the AE
  26.      */
  27.     
  28.     if ( FindAProcess( kFinderSig, kSystemType, &process) )
  29.         return( procNotFound );
  30.  
  31.     myErr = AECreateDesc( typeProcessSerialNumber, (Ptr)&process, 
  32.                             sizeof(process), &myAddressDesc);
  33.     if (myErr) return(myErr);
  34.     
  35.     /*
  36.      * Create an empty Apple Event
  37.      */
  38.     
  39.     myErr = AECreateAppleEvent( kAEFinderEvents, kAEOpenSelection, &myAddressDesc,
  40.                                 kAutoGenerateReturnID, kAnyTransactionID, &aeEvent);
  41.     
  42.     if (myErr) return(myErr);
  43.     
  44.     /*
  45.      * Make and FSSpec for the parent folder and an alias of the file.
  46.      */
  47.     
  48.     FSMakeFSSpec( theDoc->vRefNum, theDoc->parID, 0L, &dirSpec);
  49.     NewAlias( nil, &dirSpec, &dirAlias);
  50.     NewAlias( nil, theDoc, &fileAlias);
  51.     
  52.     
  53.     /*
  54.      * Create the File list.
  55.      *
  56.      */
  57.     
  58.     HLockHi( (Handle)dirAlias);
  59.     AECreateDesc( typeAlias, (Ptr)*dirAlias, GetHandleSize( (Handle)dirAlias), &aeDirDesc);
  60.     HUnlock( (Handle)dirAlias);
  61.     DisposeHandle( (Handle)dirAlias);
  62.     
  63.     if ( (myErr=AEPutParamDesc(&aeEvent, keyDirectObject, &aeDirDesc)) == noErr )
  64.     {
  65.         AEDisposeDesc( &aeDirDesc );
  66.         
  67.         AECreateList(nil, 0, FALSE, &fileList);
  68.         HLockHi( (Handle)fileAlias);
  69.         myErr = AECreateDesc( typeAlias, (Ptr)*fileAlias, 
  70.                                     GetHandleSize( (Handle)fileAlias), &listElem);
  71.         HUnlock( (Handle)fileAlias);
  72.  
  73.         DisposeHandle( (Handle)fileAlias);
  74.     
  75.         myErr = AEPutDesc( &fileList, 0L, &listElem);
  76.         
  77.         if (myErr) return(myErr);
  78.         
  79.     }
  80.     if (myErr) return(myErr);
  81.     
  82.     AEDisposeDesc(&listElem);
  83.     
  84.     myErr = AEPutParamDesc(&aeEvent, keySelection, &fileList);
  85.     if (myErr) return(myErr);
  86.  
  87.     myErr = AEDisposeDesc( &fileList);
  88.     if (myErr) return(myErr);
  89.     
  90.     myErr = AESend( &aeEvent, 0L, kAENoReply+kAEAlwaysInteract+kAECanSwitchLayer,
  91.                     kAENormalPriority, kAEDefaultTimeout, 0L, 0L);\
  92.                 
  93.     AEDisposeDesc(&aeEvent);
  94.     
  95.     return(myErr);
  96. }
  97.  
  98. /*
  99.  * Search though the current process list to find the given application. 
  100.  *
  101.  */
  102.  
  103. OSErr FindAProcess( OSType typeToFind, OSType creatorToFind, ProcessSerialNumberPtr processSN)
  104. {
  105. ProcessInfoRec            tempInfo;
  106. FSSpec                    procSpec;
  107. Str31                    processName;
  108. OSErr                    myErr = noErr;
  109.  
  110.     /*
  111.      * Start at begining of process list
  112.      */
  113.     
  114.     processSN->lowLongOfPSN = kNoProcess;
  115.     processSN->highLongOfPSN = kNoProcess;
  116.     
  117.     /*
  118.      * Init the process information record.
  119.      *
  120.      */
  121.     
  122.     tempInfo.processInfoLength = sizeof(ProcessInfoRec);
  123.     tempInfo.processName = (StringPtr)&processName;
  124.     tempInfo.processAppSpec = &procSpec;
  125.     
  126.     while ( (tempInfo.processSignature != creatorToFind || tempInfo.processType != typeToFind)
  127.                 || myErr != noErr)
  128.     {
  129.         myErr = GetNextProcess(processSN);
  130.         if (myErr == noErr)
  131.             GetProcessInformation( processSN, &tempInfo);
  132.     }
  133.         
  134.     return(myErr);
  135. }
  136.  
  137.